/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-09-04
 * Time: 21:58
 */
import java.util.Scanner;
public class Demo {

    public static void main(String[] args) {
    print(123);
    //------------------------------------------
    System.out.println(Sumint(10));
    //------------------------------------------
        System.out.println(sum(1729));
    }
    //1729递归求1+7+2+9
    public static int sum(int n){
        if(n < 10){
            return n %= 10;
        }
        else{
            return (n % 10) + sum(n / 10);
        }
    }
    //递归求1+2+...+10
    public static int Sumint(int n){
        if(n == 1){
            return 1;
        }
        return n + Sumint(n - 1);
    }
    //-----------------------------------
    //打印123的每一位数字成1 2 3
    public static void print(int n){
        if(n < 10){
            System.out.println(n % 10);
            return ;
        }
        print(n / 10);
        System.out.println(n % 10);
    }
}
